{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Company(object):\n",
    "    def __init__(self, employee_list):\n",
    "        self.employee = employee_list\n",
    "\n",
    "    def __getitem__(self, item):\n",
    "        \"\"\"任意一个类都可以添加魔法函数，返回item位置的值\"\"\"\n",
    "        return self.employee[item]\n",
    "\n",
    "    def __len__(self):\n",
    "        return len(self.employee)\n",
    "\n",
    "    def __str__(self):\n",
    "        \"\"\"打印时\"\"\"\n",
    "        return \",\".join(self.employee)\n",
    "\n",
    "    def __repr__(self):\n",
    "        \"\"\"shell中\"\"\"\n",
    "        return \"shell: \" + \",\".join(self.employee)\n",
    "\n",
    "\n",
    "company = Company([\"tom\", \"bob\", \"jane\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "shell: tom,bob,jane"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "company"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
